import ConnectSolanaWallet from '../../components/connectSolanaWallet'

import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import * as web3 from "@solana/web3.js";



const Home: React.FC = () => {

  const { connection } = useConnection();
  const { publicKey, sendTransaction } = useWallet();

  const ping = async () => {

    if (!connection || !publicKey) {
      return;
    }
    const tx = new web3.Transaction();

    const instruction = new web3.TransactionInstruction({
      keys: [{
        pubkey: publicKey,
        isSigner: true,
        isWritable: false
      }],
      // programId: new web3.PublicKey("Fg6PaFpoGXkYsidMpWTK6W2beZ7FEfcYkg476zPFsLnS"), // 类似于合约地址
      programId: web3.SystemProgram.programId,
      // data: Buffer.from("ping", "utf8"),
    });

    tx.add(instruction);
    const signature = await sendTransaction(tx, connection);

    console.log(signature);
  }

  return (
    <div>TEST
      <ConnectSolanaWallet />

      <button onClick={ping}>Ping!</button>
    </div>
  )
}

export default Home